<?php

/**
 * Controller_studentCount
 * 学生统计
 */

class Controller_studentCount extends MyApp {

	public function __construct()
	{

		parent::__construct();
		$this->model->record 	= YOU::loadModel('record');
		$this->model->excel    	= YOU::loadModel('excel');
		$this->model->semester 	= YOU::loadModel('semester');
		$this->model->baseset 	= YOU::loadModel('baseset');
		$this->model->grade 	= YOU::loadModel('grade');
		$this->model->class 	= YOU::loadModel('class');
		$this->model->log    	= YOU::loadModel('log');
		
		
		$this->s_type = $this->model->baseset->getRow('baseset_type');
		$pid = $this->model->baseset->getRow('baseset_province');
		$pid = $pid['baseset_province'].'0000';

		 $p = $this->db->fetchRow("select province_name from tbl_province where province_code = '{$pid}'");
        $this->s_pro = $p['province_name'];
        $cid = $this->model->baseset->getRow('baseset_city');
		$cid = $cid['baseset_city'].'00';
        //var_dump($cid);
		$s_city = $this->db->fetchRow("select city_name from tbl_city where city_code = '{$cid}'");
        $this->s_city = $s_city['city_name'];


		$did = $this->model->baseset->getRow('baseset_district');
		$did = $did['baseset_district'];
		$s_district = $this->db->fetchRow("select area from tbl_area where areaid = '{$did}'");
        $this->s_district = $s_district['area'];
        if(empty($this->s_district)){$this->s_district = "龙湖区";}

	}

	/** 首页 **/
	public function actionIndex()
	{

	}

	//**-------------------------------------- 学生 ----------------------------------**//
	/** 学生管理列表 **/
	public function actionStudentCountList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		//按条件搜索
		$where = " WHERE 1=1 ";

		//获取到页面传过来的要搜索的条件
		$student_no   = (int)$this->post->student_no;
		$student_name = $this->post->student_name;

		if (!empty($student_no)) {
			$where .= " AND student_no='{$student_no}' ";
			$this->tpl->assign("student_no", $student_no);
		}
		if (!empty($student_name)) {
			$where .= " AND student_name LIKE '%{$student_name}%' ";
			$this->tpl->assign("student_name", $student_name);
		}

		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` {$where}");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);

		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$studentcount_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` {$where} ORDER BY grade_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		foreach($studentcount_lists as $key => $value){
			$studentcount_lists[$key]['student_mode']  = $this->mode_ini[$value['student_mode']];
			$studentcount_lists[$key]['student_disability']  = $this->disability_ini[$value['student_disability']];
		}
		//var_dump($studentcount_lists);

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("studentcount_lists", $studentcount_lists);
		$this->tpl->assign("tmp", $tmp);
		$this->tpl->display('student/studentcount.list.tpl.php');

	}
	/*
	* 导出数据
	*/
	public function actionOutData()
	{
		//按条件搜索
		$where = " WHERE 1=1 ";

		//获取到页面传过来的要搜索的条件
		$student_no   = (int)$this->post->student_no;
		$student_name = $this->post->student_name;

		if (!empty($student_no)) {
			$where .= " AND student_no='{$student_no}' ";
			$this->tpl->assign("student_no", $student_no);
		}
		if (!empty($student_name)) {
			$where .= " AND student_name LIKE '%{$student_name}%' ";
			$this->tpl->assign("student_name", $student_name);
		}

		$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` {$where} ORDER BY grade_id DESC ");
		//var_dump($attend_lists);
		$rule = $this->model->record->getInfo('student_list');
		$col = array();
		foreach($rule as $k => $v){
			$col[] = $v['title'];
		}
		//var_dump($arr);exit;
		//$data_lists['0'] = $col;
		$info = array();

		foreach ($student_lists as $key => $value) {
			$i = 0;
			//var_dump($value);exit;
			$value['student_school'] = ' '.$value['student_school'];
			$value['student_card'] = ' '.$value['student_card'];
			$value['student_tel'] = ' '.$value['student_tel'];
			foreach ($rule as $k => $v){

				// $arr[] = $v['name'];
				//var_dump($v['name']);exit;
				switch ($v['name']){
                    case  'grade_id':
                        $grade_data = $this->db->fetchRow("select grade_name from tbl_grade WHERE grade_id = '{$value[$v['name']]}'") ;
                        $info[$i] = $grade_data['grade_name'];
                        break;
                    case  'class_id':
                        $class_data = $this->db->fetchRow("select class_name from tbl_class WHERE class_id = '{$value[$v['name']]}'") ;
                        $info[$i] = $class_data['class_name'];
                        break;

                    case  'student_over':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'student_sex':
                        $info[$i] = $this->sex_ini[$value[$v['name']]];
                        break;
                    case  'is_work':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'is_alone':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'is_study':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'is_help':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
					case  'is_martyr':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
                    case  'is_subsidy':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'is_left':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
                    case  'is_stay':
                        $info[$i] = $this->yes_ini[$value[$v['name']]];
                        break;
					case  'student_disability':
						$info[$i] = $this->disability_ini[$value[$v['name']]];
						break;
					case  'student_registered':
						$info[$i] = $this->registered_ini[$value[$v['name']]];
						break;
					case  'student_mode':
						$info[$i] = $this->mode_ini[$value[$v['name']]];
						break;
					case  'student_classes':
						$info[$i] = $this->classes_ini[$value[$v['name']]];
						break;
					case  'student_state':
						$info[$i] = $this->state_ini[$value[$v['name']]];
						break;
					case  'student_type':
						$info[$i] = $this->etype_ini[$value[$v['name']]];
					default:
						$info[$i] = $value[$v['name']];
				}
				$i++;

			}
			$data_lists[$key] = $info;



		}
		//var_dump($data_lists);exit;
		// 模板标题
		$this->model->excel->excel_ini['studentcount']['title'] = "学生统计表";
		$this->model->excel->excel_ini['studentcount']['col'] = $col;
		$this->model->excel->outData("studentcount", $data_lists);

		//$this->tpl->display();
	}


	//**---------------------------------学生统计汇总表 -------------------------------**//
	/** 学生统计汇总列表 **/
	public function actionStudentTotalList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
		//年级
		$grade_lists = $this->model->grade->getAll();
		// 全校总人数
		$student_count = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student`");
		// 全校女生总数
		$student_woment = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE student_sex =0");
		// 全校男生总数
		$student_ment = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE student_sex =1");
		// 全校班级总数
		$class_count = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_class`");

		foreach($grade_lists as $key => $value){

			// 取得班级列表
			$grade_lists[$key]['class_lists'] = $this->model->class->getListByGrade($value['grade_id']);

			foreach ($grade_lists[$key]['class_lists'] as $k => $v){
                $row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE class_id='{$v['class_id']}' AND student_sex='1' ");
                $grade_lists[$key]['class_lists'][$k]['man'] = $row['count'];
                $men = $row['count'];
                $row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE class_id='{$v['class_id']}' AND student_sex='0' ");
                $grade_lists[$key]['class_lists'][$k]['women'] = $row['count'];
                $women = $row['count'];
                $all = $men + $women ;
                $grade_lists[$key]['class_lists'][$k]['all'] = $all ;
            }
           
            // 班数
			$grade_lists[$key]['class_count'] = count($grade_lists[$key]['class_lists']);

			// 男生数量
			$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE grade_id='{$value['grade_id']}' AND student_sex='1' ");
			$grade_lists[$key]['men_count']  = $row['count'];
            $m = $row['count'];

			// 女生数量
			$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_student` WHERE grade_id='{$value['grade_id']}' AND student_sex='0' ");
			$grade_lists[$key]['women_count']  = $row['count'];
            $w = $row['count'];
            $grade_lists[$key]['all'] = $m + $w;

		}
	

		$this->tpl->assign("student_woment", $student_woment);
		$this->tpl->assign("student_ment", $student_ment);
		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("class_count", $class_count);
		$this->tpl->assign("student_count", $student_count);
		$this->tpl->display('student/studenttotal.list.tpl.php');

	}

	//**--------------------------------------学生户籍表（统计) ------------------------------------**//
	/** 学生统计汇总列表 **/
	public function actionCensusCountList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
		//获取省市区
		//        $info = $this->db->fetchRow("SELECT b.province_name,c.city_name,d.area_name FROM
		//`tbl_baseset` as a,`tbl_province` as b,`tbl_city` as c,`tbl_area`as d where a.baseset_province = b.province_id AND
		//a.baseset_city = c.city_id AND a.baseset_district = d.area_id");
		//        var_dump($info);exit;

		$lists = array();

		$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` ");
		$lists['all'] = $row['count'];
		//本地
		$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` like '%{$this->s_city}%' AND `student_register` like '%{$this->s_district}%' ");
		$lists['city'] = $row['count'];
		//本地外区
		$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` like '%{$this->s_city}%' AND `student_register` not like '%{$this->s_district}%' ");
		$lists['nocity'] = $row['count'];
		//本省外市
		$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` like '%{$this->s_pro}%'");

		$lists['province'] = $row['count']-$lists['city']-$lists['nocity'];
		//外省
		$lists['noprovince'] = $lists['all'] - $lists['province'];

		//var_dump($lists);
		$grade_lists = $this->db->fetchAll("SELECT grade_id,grade_name FROM `tbl_grade` ");

		foreach ($grade_lists as $key => $value){
			$grade_id = $value['grade_id'];
			$where  = "`grade_id` = {$grade_id}";
			$all = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` WHERE {$where}");
			$lists[] = $all['count(1)'];

			$city = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_city}%' AND `student_register` like '%{$this->s_district}%' ");
			$lists[] = $city['count(1)'];

			$nocity = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_city}%' AND `student_register` not like '%{$this->s_district}%' ");
			$lists[] = $nocity['count(1)'];

			$province = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_pro}%'");
			$lists[] = $province['count(1)']-$city['count(1)']-$nocity['count(1)'];

			$lists[] = $all['count(1)'] - $province['count(1)'];
		}
		//var_dump($lists);
		//获取学校信息
		$name = $this->model->baseset->getRow('baseset_name');
		$ename = $this->model->baseset->getRow('baseset_ename');
		$user_id = $this->user['user_id'];
		$who = $this->model->user->getNameById($user_id);
		$date = date("Y-m-d");
		$this->tpl->assign("name", $name['baseset_name']);
		$this->tpl->assign("ename", $ename['baseset_ename']);
		$this->tpl->assign("who", $who);
		$this->tpl->assign("date", $date);
		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("lists", $lists);
		$this->tpl->display('student/censuscount.list.tpl.php');

	}

	public function actioncenout()
	{
		
		$lists = array();

		$all = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` ");
		$lists[] = $all['count(1)'];

		$city = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where `student_register` like '%{$this->s_city}%' AND `student_register` like '%{$this->s_district}%' ");
		$lists[] = $city['count(1)'];

		$nocity = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where `student_register` like '%{$this->s_city}%' AND `student_register` not like '%{$this->s_district}%' ");
		$lists[] = $nocity['count(1)'];

		$province = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where `student_register` like '%{$this->s_pro}%'");
		$lists[] = $province['count(1)']-$city['count(1)']-$nocity['count(1)'];

		$lists[] = $all['count(1)'] - $province['count(1)'];

		//var_dump($lists);
		$grade_lists = $this->db->fetchAll("SELECT grade_id,grade_name FROM `tbl_grade` ");

		$rules = array('学生总数','本区户籍','本市外区户籍','本省外市户籍','外省户籍');

		foreach ($grade_lists as $key => $value){
			$rule = array($value['grade_name'].'学生总数','本区户籍','本市外区户籍','本省外市户籍','外省户籍');
			$rules = array_merge($rules, $rule);
			$grade_id = $value['grade_id'];
			$where  = "`grade_id` = {$grade_id}";
			$all = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` WHERE {$where}");
			$lists[] = $all['count(1)'];

			$city = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_city}%' AND `student_register` like '%{$this->s_district}%' ");
			$lists[] = $city['count(1)'];

			$nocity = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_city}%' AND `student_register` not like '%{$this->s_district}%' ");
			$lists[] = $nocity['count(1)'];

			$province = $this->db->fetchRow("SELECT count(1) FROM `tbl_student` where {$where} AND `student_register` like '%{$this->s_pro}%'");
			$lists[] = $province['count(1)']-$city['count(1)']-$nocity['count(1)'];

			$lists[] = $all['count(1)'] - $province['count(1)'];
		}
		$data_lists[]=$lists;
		//cencount
		$rule = array('学生总数','本区户籍','本市外区户籍','本省外市户籍','外省户籍');
		$this->model->excel->excel_ini['cencount']['col'] = $rules;
		$this->model->excel->outData("cencount", $data_lists);

	}

	public function actionplace()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
		
		$grade_lists = $this->db->fetchAll("SELECT grade_id,grade_name FROM `tbl_grade_up` where is_now=1");
		
        $lists = array();
		$len = count($grade_lists);
		
		//全部
		for($p=0;$p<21;$p++){//二维数组lists的最外层一次循环为一行数据
			for($i = -5;$i<=$len;$i++){//处理每列数据  总  女   年级++
                if($i==-5){//毕业生
                    $where = ' 1=1 ';
                }elseif($i==-4){//新生
                    $where = " `student_variation` like '%新生%' ";
                }elseif($i==-3){//学前教育
                    $where = ' is_study = 1 ';
                }elseif($i==-2){//总
					$where = ' 1=1 ';
				}elseif ($i==$len){//总
                    $where = ' 1=1 ';
                }elseif ($i==-1){//女
					$where = ' `student_sex` = 0 ';
				}else{//年级
					$name = $grade_lists[$i]['grade_id'];
					$where = " `grade_id` = {$name} ";
				}
				switch ($p){//name 用于区分是哪一行
					case 0:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` WHERE {$where}");
						$name = 'all';
						
						break;
					case 1:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_sex`= 0 AND {$where}");

						$name = 'girl';
						break;
					case 2:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_nation` not like '%汉%' AND {$where}");

						$name = 'nation';
						break;
					case 3:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_state` =3  AND {$where}");

						$name = 'state';
						break;
					case 4:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_state` =3 AND `student_sex`= 0 AND {$where}");

						$name = 'stategirl';
						break;

					case 5:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_mode` =1  AND {$where}");

						$name = 'model';
						break;
					case 6:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` not like '%{$this->s_district}%' AND {$where}");

						$name = 'nocity';
						break;
					case 7:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` not like '%{$this->s_pro}%' AND {$where} ");

						$name = 'noprovince';
						break;

					case 8:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_register` NOT like '%{$this->s_city}%' AND `student_register`  like '%{$this->s_pro}%' AND {$where} ");

						$name = 'province';
						break;
					case 9:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_registered` = 1 AND {$where} ");

						$name = 'farm';
						break;

					case 10:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_registered` = 1 AND `student_register` not like '%{$this->s_pro}%' AND {$where}");

						$name = 'farmnop';
						break;
					case 11:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_registered` = 1 AND `student_register` NOT like '%{$this->s_city}%' AND `student_register`  like '%{$this->s_pro}%' AND {$where}");

						$name = 'farmp';
						break;

					case 12:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `is_left` ='是'  AND {$where}");

						$name = 'left';
						break;
					case 13:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` !=0  AND {$where}");

						$name = 'read';
						break;
					case 14:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` !=0 AND 'student_sex' = 0 AND {$where}");

						$name = 'readgirl';
						break;

					case 15:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` !=0 AND `student_nation` NOT LIKE '汉' AND {$where}");

						$name = 'readnation';
						break;
					case 16:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` !=0 AND `student_mode` =1  AND {$where}");

						$name = '1readmode';
						break;
					case 17:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` =1  AND {$where}");

						$name = '1disability';
						break;

					case 18:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` =2  AND {$where}");

						$name = '2disability';
						break;
					case 19:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` =3  AND {$where}");

						$name = '3disability';
						break;
					case 20:
						$row = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_student` where `student_disability` =4  AND {$where}");

						$name = '4disability';
						break;
				}

				$list[] = $row['count'];

			}
			$lists[$name] = $list;
			unset($list);
		}
		//var_dump($lists);


		//年龄
		$age = 5;
		if($this->s_type['baseset_type'] !='1'){$age = $age + 6;}
        $this->tpl->assign('age',$age);
		//if不是小学则+6
		$now = date('Y-m-d',time());
		//$row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) <= {$age} ; ");
		//$list['age0'] = $row['count'];
		for ($ii=0;$ii<11;$ii++){
			$age++;
            for($i = -5;$i<=$len;$i++){//处理每列数据  总  女   年级++
                if($i==-5){//毕业生
                    $where = ' 1=1 ';
                }elseif($i==-4){//新生
                    $where = " `student_variation` like '%新生%' ";
                }elseif($i==-3) {//学前教育
                    $where = ' is_study = 1 ';
                }elseif($i==-2){//总
                    $where = ' 1=1 ';
                }elseif ($i==$len){//总
                    $where = ' 1=1 ';
                }elseif ($i==-1){//女
                    $where = ' `student_sex` = 0 ';
                }else{//年级
                    $name = $grade_lists[$i]['grade_id'];
                    $where = " `grade_id` = {$name} ";
                }
                switch ($ii){
                    case 0:
                        $row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) <= {$age}   AND {$where}  ");
                        break;
                    case 10:
                        $row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) >= {$age} AND {$where} ");
                        break;
                    default:
                        $row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) = {$age}   AND {$where} ");

                }
                $name = $ii.'age';

                $list[] = $row['count'];


            }
            $lists[$name] = $list;
            unset($list);
//			$row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) = {$age} ; ");
//			$list['age'.$ii] = $row['count'];
		}
		//var_dump($lists);
		//$age++;
		//$row = $this->db->fetchRow("SELECT COUNT(1) as count from tbl_student WHERE FLOOR(datediff('{$now}',student_birth)/365) >= {$age} ; ");
		//$list['age'.$ii] = $row['count'];



        $semester_data = $this->model->semester->getNew();
        $smname = $semester_data['semester_xname'];
        $this->tpl->assign('smname',$smname);
        $row = $this->model->baseset->getRow('baseset_name');
        $sname = $row['baseset_name'];
        $row = $this->model->baseset->getRow('baseset_code');
        $scode = $row['baseset_code'];
        $this->tpl->assign('sname',$sname);
        $this->tpl->assign('scode',$scode);

		//获取学校信息
		$name = $this->model->baseset->getRow('baseset_name');
		$ename = $this->model->baseset->getRow('baseset_ename');
		$user_id = $this->user['user_id'];
		$who = $this->model->user->getNameById($user_id);
		$date = date("Y-m-d");
		$this->tpl->assign("name", $name['baseset_name']);
		$this->tpl->assign("ename", $ename['baseset_ename']);
		$this->tpl->assign("who", $who);
		$this->tpl->assign("date", $date);
		$this->tpl->assign("len", $len);
		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("lists", $lists);
		$this->tpl->display('student/splace.list.tpl.php');
	}

	public function actionschange()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);
		
		
        $semester_id     	= $this->get->semester_id;
        $row = $this->model->baseset->getRow('baseset_name');
        $sname = $row['baseset_name'];
        $row = $this->model->baseset->getRow('baseset_code');
        $scode = $row['baseset_code'];
        $this->tpl->assign('sname',$sname);
        $this->tpl->assign('scode',$scode);
        if(empty($semester_id)){
            // 获取当前学期id,获得学年学期名称
            $semester_data = $this->model->semester->getNew();
            $semester_id   = $semester_data['semester_id'];
        }

        $row = $this->db->fetchRow("select start_time,end_time from tbl_semester WHERE semester_id = '{$semester_id}'");
        $start_time = $row['start_time'];
        $end_time = $row['end_time'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_student WHERE  create_time<='{$start_time}' ");
        $nadd = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE  schange_time<='{$start_time}' ");
        $nred = $row['count'];
        $nall = $nadd - $nred;
        $this->tpl->assign('nall',$nall);
        //找上一个学期
        $row  = $this->db->fetchRow("select * from `tbl_semester` WHERE `end_time` <= '{$start_time}' ORDER BY `end_time` DESC limit 1");
        $l_stime = $row['start_time'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_student WHERE  create_time<='{$l_stime}' ");
        $ladd = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE  schange_time<='{$l_stime}' ");
        $lred = $row['count'];
        $lall = $ladd - $lred;
        $this->tpl->assign('lall',$lall);
        //$e = date('Y-m',$end_time);
        $row = $this->db->fetchRow("select count(1) as count from tbl_student WHERE `student_variation` like '%新生%' AND create_time<='{$end_time}' AND create_time>='{$start_time}'");
        $add1 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_student WHERE `student_variation` like '%复学%' AND create_time<='{$end_time}' AND create_time>='{$start_time}'");
        $add2 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_student WHERE `student_variation` like '%转入%' AND create_time<='{$end_time}' AND create_time>='{$start_time}'");
        $add3 = $row['count'];

        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%毕业%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red1 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%结业%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red2 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%休学%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red3 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%退学%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red4 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%死亡%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red5 = $row['count'];
        $row = $this->db->fetchRow("select count(1) as count from tbl_schange WHERE `student_variation` like '%转出%' AND schange_time<='{$end_time}' AND schange_time>='{$start_time}'");
        $red6 = $row['count'];

        $this->tpl->assign('add1',$add1);
        $this->tpl->assign('add2',$add2);
        $this->tpl->assign('add3',$add3);
        $this->tpl->assign('red1',$red1);
        $this->tpl->assign('red2',$red2);
        $this->tpl->assign('red3',$red3);
        $this->tpl->assign('red4',$red4);
        $this->tpl->assign('red5',$red5);
        $this->tpl->assign('red6',$red6);
        // 所有学期名称
        $semester_lists =  $this->model->semester->getIni();
        $this->tpl->assign("semester_id", $semester_id);
        $this->tpl->assign("semester_lists", $semester_lists);
        $this->tpl->display('student/schange.list.tpl.php');

    }
}

?>